package com.fndsoft.logstorage.ui;

import java.io.BufferedReader;


import java.io.File;
import java.io.InputStreamReader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.fndsoft.logstorage.R;
import com.fndsoft.logstorage.component.colog.COLog;
import com.fndsoft.logstorage.util.FileUtils;
import com.fndsoft.logstorage.util.HttpDownload;

public class MainActivity extends Activity {
	private Button btnMain;
	private EditText e1;
	private EditText e2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		btnMain = (Button) this.findViewById(R.id.btnMain);
		e1 = (EditText) findViewById(R.id.e1);
		e2 = (EditText) findViewById(R.id.e2);
		
		
		btnMain.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
			//COLog.d(MainActivity.this.getClass().getSimpleName(),"我点击了Button");
			/*COLog l = new COLog();
			l.d(MainActivity.this.getClass().getSimpleName(),"我点击了Button");
			System.out.println("Log:~~~~" + l.toString() );*/
				COLog.d("aaaaaaa~~~");
				COLog.e("gggggggg~~~~~~");
				String text1 = e1.getText().toString();
				String text2 = e2.getText().toString();
				int i1 = 0;
				boolean flag = true;
				try{
					i1 = Integer.parseInt(text1);
				} catch(NumberFormatException e ) {
					COLog.d(e.toString());
					/*Thread t = new ErrorThread();
					t.start();
					flag = false;*/
					e.printStackTrace();
				} 
				Intent intent = new Intent();
				intent.setClass(MainActivity.this, LogActivity.class);
				startActivity(intent);
			}
		});
	}
	
	class ErrorThread extends Thread{
		@Override
		public void run() {
			Process  logcatProcess = null;
			HttpDownload hd = new HttpDownload();
			try {
                /** 获取系统logcat日志信息 */
                //相当于在命令行运行  logcat -s dalvikm ,  -s表示过滤， 第三个参数表示过滤的条件。如果没有第三个参数，数组长度2，肯定也是可以的。下面有logcat的使      用方法
                String[] running=new String[]{ "logcat","*:* *:*" };
                logcatProcess = Runtime.getRuntime().exec(running);
                hd.downFile2("bobos" + File.separator, "new1.txt", logcatProcess.getInputStream());
			}  catch (Exception e) {
                e.printStackTrace();
			}
		}
	}
	
	public String[] filter(String msg) {
		String[] running = new String[] {"logcat",msg};
		return running;
	}
	
	class MyThread extends Thread {
		public void run() {
			Process  logcatProcess = null;
			HttpDownload hd = new HttpDownload();
			/*BufferedReader bufferedReader = null;
			StringBuffer sb = new StringBuffer();*/
			 try {
                 /** 获取系统logcat日志信息 */
                 //相当于在命令行运行  logcat -s dalvikm ,  -s表示过滤， 第三个参数表示过滤的条件。如果没有第三个参数，数组长度2，肯定也是可以的。下面有logcat的使      用方法
                 String[] running=new String[]{ "logcat","COLog:* *:S"};
                 logcatProcess = Runtime.getRuntime().exec(running);
                 hd.downFile2("bobos" + File.separator, "new7.txt", logcatProcess.getInputStream());
                 System.out.println("Log ~~~~~");
                 //fu.write2SDFromInput("ffff" + File.separator, "hhhhh", logcatProcess.getInputStream());
                 
                 /*bufferedReader = new BufferedReader(new InputStreamReader(
                                 logcatProcess.getInputStream()));

                 String line;
                 System.out.println("Loggggg" +sb);
                 while ((line = bufferedReader.readLine()) != null) {
                         //读出每行log信息
                         System.out.println(line);
                         sb.append(line);
                 }
                 System.out.println("Log ~~~~~" + sb);*/
                 //bufferedReader.close();
         } catch (Exception e) {
                 e.printStackTrace();
         }
			
		}
	}
}
